package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.ApiParam;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("nursing")
public class NursingPlanController {
  @Autowired
  private NursingPlanService nursingPlanService;

  @GetMapping("plan")
  public ResponseResult<List<NursingPlanVo>> listAll() {
    List<NursingPlanVo> nursingPlanVo = nursingPlanService.listAll();
    return ResponseResult.success(nursingPlanVo);
  }

  @PostMapping("plan")
  public ResponseResult add(@RequestBody NursingPlanDto nursingPlanDto) {
     nursingPlanService.add(nursingPlanDto);
    Set<String> set = new HashSet<>();
    return ResponseResult.success();
  }

  @GetMapping("plan/search")
  public ResponseResult search(
          @ApiParam(value = "页码（默认为1")
          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
          @ApiParam(value = "每页大小（默认为10）")
          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
          @ApiParam(value = "护理计划名称")
          @RequestParam(value = "name", required = false) String name,
          @ApiParam(value = "护理计划状态：0-禁用，1-启用")
          @RequestParam(value = "status", required = false) Integer status) {
    PageResponse<NursingPlanVo> planVoPageResponse =nursingPlanService.search(pageNum, pageSize, name, status);
    return ResponseResult.success(planVoPageResponse);
  }
  @GetMapping("plan/{id}")
  public ResponseResult getById(@PathVariable("id") Long planId) {
    NursingPlanVo nursingPlanVo = nursingPlanService.getById(planId);
    return ResponseResult.success(nursingPlanVo);
  }
  @PutMapping("plan/{id}")
  public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto) {
    nursingPlanService.update(nursingPlanDto);
    return ResponseResult.success();
  }

  @PutMapping("{id}/status/{status}")
  public ResponseResult isActive(@PathVariable("id") String id, @PathVariable("status") Integer status) {
    nursingPlanService.isActive(id, status);
    return success();
  }


  @DeleteMapping("plan/{id}")
  public ResponseResult deleteByID(@PathVariable("id") String id) {
    nursingPlanService.deleteById(id);
    return success();
  }
}
